# 一、读操作
# 1. read（）/ readline()
# f = open('test.txt', 'r', encoding='utf-8')
# 读取1个字符
# print(f.read(1))
# 读取一行
# print(f.readline())
# 读取全部行(返回一个列表，每个值表示一行数据)
# print(f.readlines())
# 读取全部
# print(f.read())
# f.close()

# 2. readable 判断文件是否可读
# f = open('test.txt', 'r', encoding='utf-8')
# print(f.readable())
# print(f.read())
# print(f.readable())
# f.close()


# 二、写模式
# 1. write()
f = open('test.txt', 'w', encoding='utf-8')
f.write(str(['hello world\n', 'hello world\n']))

# 2. writelines()  将可迭代对象写入文件
f = open('test.txt', 'w', encoding='utf-8')
f.writelines(['hello world\n', 'hello world\n'])
f.close()

# 3. writable 是否可写
f = open('test.txt', 'w', encoding='utf-8')
print(f.writable())
